package com.zhixin.fans.ks.ui.main.mutual;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.eenie.common.ui.PicPreviewActivity;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.res.MutualContent;

import java.util.List;


public class MutualAdapter extends BaseQuickAdapter<MutualContent, BaseViewHolder> implements BaseQuickAdapter.OnItemClickListener {
    public MutualAdapter(@Nullable List<MutualContent> data) {
        super(R.layout.item_mutual, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MutualContent item) {

        helper.setText(R.id.tv_user_name, item.getNickname())
                .setText(R.id.tv_mutual_time, item.getAdd_time())
                .setText(R.id.tv_mutual_talk_count, item.getDis_num())
                .setText(R.id.tv_talk_count, item.getZan_num())
                .setText(R.id.tv_mutual_content, item.getDesc());

        RecyclerView recyclerView = helper.getView(R.id.rv_pics);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        recyclerView.setAdapter(new MutualImgAdapter(item.getImg_url(), this));

        recyclerView.setVisibility(TextUtils.isEmpty(item.getImg_url()) ? View.GONE : View.VISIBLE);

        Glide.with(mContext).asBitmap().load(item.getHead_pic()).into((ImageView) helper.getView(R.id.img_user_header));


    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        String url = adapter.getItem(position).toString();
        PicPreviewActivity.start(mContext,url);
    }
}
